# coding: utf8
# try something like
def index(): return dict(message="hello from todoshell application")
def tasks():
    #recores=db().select(db.task.ALL,orderby=db.task.id)
    #return dict(records=SQLTABLE(records))
    records=db(db.task.queue_id==request.vars.queue).select(orderby=db.task.id)
    form=SQLFORM(db.task,fields=['queue_id','status'])
    return dict(form=form,records=records)
def todo_tasks():
    #recores=db().select(db.task.ALL,orderby=db.task.id)
    #return dict(records=SQLTABLE(recores))
    records=db(db.task.queue_id==request.vars.queue).select(orderby=db.task.id and db.task.status==0)
    form=SQLFORM(db.task,fields=['queue_id'])
    return dict(form=form,records=records)    
def done_tasks():
    #recores=db().select(db.task.ALL,orderby=db.task.id)
    #return dict(records=SQLTABLE(recores))
    records=db(db.task.queue_id==request.vars.queue).select(orderby=db.task.id and db.task.status==1)
    form=SQLFORM(db.task,fields=['queue_id'])
    return dict(form=form,records=records)  
def show():
    id=request.vars.id
    tasks=db(db.task.id==id).select()
    if not len(tasks): redirect(URL(r=request,f='tasks'))
    return dict(task=tasks[0])

def new_task():
    form=SQLFORM(db.task,fields=['subject','comment',\
        'create_time','queue_id'])
    if form.accepts(request.vars,session):
        redirect(URL(r=request,f='tasks'))
    return dict(form=form)
